<?php

namespace App\Providers;


use App\Enum\ZeroOneEnum;
use App\Services\AdminService\Models\AdminMessagesModel;
use App\Services\AdminService\Models\AdminPermissionsModel;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);
        view()->composer('admin.layout', function ($view) {
            $menus = AdminPermissionsModel::with([
                'childs' => function ($query) {
                    $query->with(['childs' => function ($query) {
                        $query->with('icon')->where('is_page', ZeroOneEnum::ONE);
                    }, 'icon'])->where('is_page', ZeroOneEnum::ONE);
                }, 'icon'])
                ->where('parent_id', ZeroOneEnum::ZERO)->where('is_page', ZeroOneEnum::ONE)->orderBy('sort', 'desc')->get();
//            $unreadMessage = AdminMessagesModel::where('read', 1)->where('accept_uuid', auth()->user()->uuid)->count();
            $view->with('menus', $menus);
//            $view->with('unreadMessage', $unreadMessage);
        });
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
